package com.yihu.wlyy.repository;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.yihu.wlyy.entity.WlyyTalkGroupMember;

public interface TalkGroupMemberDao extends PagingAndSortingRepository<WlyyTalkGroupMember, Long> {


	/**
	 * 获取某个讨论组的某个成员信息
	 * 
	 * @param groupCode
	 * @param memberCode
	 * @return
	 */
	WlyyTalkGroupMember findByGroupCodeAndMemberCode(String groupCode,String memberCode);
	
	/**
	 * 通过讨论组标识查找对应讨论组成员
	 * 
	 * @param groupCode
	 * @return
	 */
	@Query("select a from WlyyTalkGroupMember a where a.groupCode = ?1 and a.status = 1")
	List<WlyyTalkGroupMember> findByGroupCode(String groupCode);
	
	
	/**
	 * 统计某个医生讨论组个数
	 * 
	 * @param memberCode
	 * @return
	 */
	@Query("select count(*) from WlyyTalkGroup tg,WlyyTalkGroupMember tgm where tg.code = tgm.groupCode and tgm.memberCode = ?1 and tg.type <> 1")
	long countByMemberCode(String memberCode);
	
	/**
	 * 统计某个成员某个时间范围讨论组个数
	 * 
	 * @param memberCode
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	@Query("select count(tgm) from WlyyTalkGroupMember tgm where tgm.memberCode = ?1 and czrq >= ?2 and czrq <= ?3")
	long countByMemberCodeAndCzrq(String memberCode,Date startDate,Date endDate);
}
